package com.tarrant.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.tarrantcounty.entity.Employee;

/**
 * Servlet implementation class PayEmployeeSerrvlet
 */
@WebServlet("/payemp")
public class PayEmployeeSerrvlet extends HttpServlet
{
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException
	{

		HttpSession session = request.getSession(true);
		String spa = request.getParameter("payamount");
		try
		{
			float amount = Float.parseFloat(spa);
			
			// validate !!!!!
			Employee emp = (Employee)session.getAttribute("currentEmployee");
			float net = emp.pay(amount);
			
			request.setAttribute("msg", "paid a net of " + net);
		} catch (NumberFormatException e)
		{
			request.setAttribute("msg", "Type in a value number!!!");
		}
		
		RequestDispatcher rd = getServletContext().
				getRequestDispatcher("/payemp.jsp");
		rd.forward(request, response);
		
	}

}
